package com.qf.lanzhou.blog.api.service.impl;

import com.qf.lanzhou.blog.api.dao.CommentDao;
import com.qf.lanzhou.blog.api.dao.Impl.CommentDaoImpl;
import com.qf.lanzhou.blog.api.service.CommentService;

import java.util.List;

/**
 * @author 是柠檬甜
 * @ClassName CommentServiceImpl
 * @description 评论服务层接口实现类
 * @date 2020/12/17 14:51
 * @modifier 是柠檬甜
 * @date 2020-12-17 14:51
 * @Version V1.0
 */
public class CommentServiceImpl implements CommentService {
    private CommentDao commentDao=new CommentDaoImpl();
    @Override
    public List showComment(String userName, Long articleId,String commentStatus) {
        List commentList = commentDao.select(userName, articleId,commentStatus);
        if (commentList.size()==0){
            throw new RuntimeException("暂无评论");
        }
        return commentList;
    }

    @Override
    public String addComment(String content, String userName, Long articleId) {
        Boolean result = commentDao.insert(content, userName, articleId);
        if (!result){
            throw new RuntimeException("系统繁忙，请稍后再试");
        }
        return "评论成功";
    }

    @Override
    public Boolean changeStatus(String commentStatus) {
        Boolean status = commentDao.update(commentStatus);
        if (!status){
            throw new RuntimeException("系统繁忙，读取失败");
        }
        return true;
    }
}
